#include <bits/stdc++.h>
using namespace std;
const int N = 510;
long double a[N][N];
const long double eps = 1e-8;
int c[N];
long long ans = 0;

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> a[i][j];
  for (int i = 0; i < n; ++i) cin >> c[i];
  int dim = 0;
  for (int j = 0; j < m; ++j) {
    int now = -1;
    for (int i = dim + 1; i < n; ++i)
      if (abs(a[i][j]) > eps && (now == -1 || c[i] < c[now])) now = i;

    if (now == -1) continue;
    ans += c[now];
    dim++;
    swap(a[now], a[dim]);
    swap(c[now], c[dim]);
    for (int i = 1; i <= n; ++i)
      if (dim != i && abs(a[i][j]) > eps) {
        long double rate = a[i][j] / a[dim][j];
        for (int k = j; k <= m; ++k) a[i][k] -= a[dim][k] * rate;
      }
  }
  cout << dim << ' ' << ans << endl;
}
